const HB = require("./inc/baseHb");
const STATE = require("../states/gunstates"); 

cc.Class({
    extends: HB,

    properties: {},

    onLoad(){
        this.setAttr("_gunStateV" , STATE.INPAOTAI );
        
        //this.node.opacity = 1;
    },

    resetGunpos(){
        if(!this._gun) return;
        this._gun.node.active = true;
        const thispos = this.node.parent.convertToWorldSpaceAR(this.node.getPosition());
        let topos = this._gun.node.parent.convertToNodeSpaceAR(thispos);
        topos = topos.add(cc.v2(0,10));

        cc.tween( this._gun.node)
        .to(.08 , {x:topos.x , y:topos.y, scale : 1})
        .call(()=>{
            this._gun.flymodel( false );
        })
        .start();
        //this._gun.node.setPosition( this._gun.node.parent.convertToNodeSpaceAR(thispos) );
    },

    // setGunPosition(){
    //     if(this._gun){
    //         let gunnode = this._gun.node;
    //         gunnode.parent && gunnode.setPosition( gunnode.parent.convertToNodeSpaceAR( this.node.convertToWorldSpaceAR(cc.v2(0,0)) ))
    //     }
    // },

    shoot( toNode , model ){
        if(!this._gun) return;
        if( !this._gun.isState(STATE.INPAOTAI) ) return;
        this._gun.shoot( toNode , model );
    },

    update(dt){
    }
});
